﻿'         This file is Copyright © 2008-2012 Billy O'Neal and Aommaster
'                            All rights reserved.
'
' This file is released under the 2-Clause BSD license, included in LICENSE.TXT
'                           and on the MHWT website
Friend Class EditCan
    Private can As Speech
    Private Sub handleDelete()
        Me.Close()
    End Sub
    Private Sub HandleChanges()
        canNameBox.Text = can.name
        canDiscBox.Text = can.Description
        canLogsBox.Text = can.LogsGenerated
        safeBox.Checked = can.SafeMode
        canTextBox.Text = can.Text
    End Sub

    Public Sub New(ByRef canToEdit As Speech)
        can = canToEdit
        InitializeComponent()
        HandleChanges()
        AddHandler can.Modified, AddressOf HandleChanges
        AddHandler can.Deleted, AddressOf handleDelete
    End Sub

    Private Sub canNameBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles canNameBox.TextChanged
        can.name = canNameBox.Text
    End Sub

    Private Sub canDiscBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles canDiscBox.TextChanged
        can.Description = canDiscBox.Text
    End Sub

    Private Sub canLogsBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles canLogsBox.TextChanged
        can.LogsGenerated = canLogsBox.Text
    End Sub

    Private Sub safeBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles safeBox.CheckedChanged
        can.SafeMode = safeBox.Checked
    End Sub

    Private Sub canTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles canTextBox.TextChanged
        can.Text = canTextBox.Text
    End Sub

    Private Sub editCan_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        RemoveHandler can.Modified, AddressOf HandleChanges
        RemoveHandler can.Deleted, AddressOf handleDelete
    End Sub
    Private Sub steal(ByVal sender As System.Object, ByVal e As EventArgs)
        Me.Select()
    End Sub
    Private Sub Canned_Preview() Handles SpeechPreviewTab.Enter
        Dim path As String = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "preview.html")
        Dim text As New BbCodeToHtmlFormatter

        text.StartConvert(canTextBox.Text)
        PreviewBox.Url = New System.Uri(path)
    End Sub
End Class